<section class="sidebar">
@php
    use Illuminate\Support\Facades\Auth;
    use \App\Modules\Package\Models\PackageAttr;
    use \App\Modules\Shop\Shop;
    use App\Modules\User\Models\Admin;
@endphp
@auth
    @php
        $user  = Auth::user();
        if($user->is_merchant_staff == 1){
            //$shops 当前登录员工账号所绑定的门店，查看所有门店的is_photography字段，是否是婚纱门店，用于判断营销管理左侧菜单
            $shops = Shop::query()->whereIn('id', json_decode($user->shop_id, true))->get()->pluck('is_photography')->toArray();
        }
    @endphp
    <!-- Sidebar Menu -->
        <ul class="sidebar-menu tree" data-widget="tree">
            @can('shop')
                <li class="header">店铺设置</li>
                <li @if(app('request')->routeIs('admin.group*')) class="active" @endif><a
                        href="{{ route("admin.group.index") }}"><i class="fa fa-database"></i> <span>集团管理</span></a></li>
                <li @if(app('request')->routeIs('admin.shop*')) class="active" @endif><a
                        href="{{ route("admin.shop.index") }}"><i class="fa fa-database"></i> <span>门店管理</span></a></li>
            @endcan

            @can('lib')
                <li class="header">产品管理</li>
                <li @if(app('request')->routeIs('admin.package.attr*')) class="active" @endif><a
                        href="{{ route("admin.package.attr") }}"><i class="fa fa-database"></i> <span>类别</span></a></li>

                <li class="treeview">
                  <a id="dropdownSubMenu1" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link dropdown-toggle"><i class="fa fa-bookmark-o"></i> <span>全部系列</span></a>
                  <ul aria-labelledby="dropdownSubMenu1" class="treeview-menu">
                    @foreach(PackageAttr::query()->get() as $item)
                        <li @if(app('request')->routeIs('admin.package.lib*') && isset($attr) && $attr == $item->id) class="active" @endif>
                            <a href="{{ route("admin.package.lib", ['attr' => $item->id]) }}"><i class="fa fa-fax"></i>
                                <span> {{ $item->name }}</span></a></li>
                    @endforeach
                  </ul>
                </li>
                
            @endcan

            @if ($user->is_merchant_staff == Admin::MERCHANT_AUTH) {{-- 如果是1的话，则是商家职员 --}}
            @can('merchant_staff_goods_and_package')
                <li class="header">套系管理</li>
                @foreach(Shop::query()->whereIn("id",json_decode($user->shop_id,true))->where(["type"=> Shop::TYPE_PHOTO])->get() as $item)
                    <li @if(app('request')->routeIs('admin.package*') && isset($shopId) && $shopId == $item->id) class="active" @endif>
                        <a href="{{ route("admin.package.index", ['shop_id' => $item->id, 'category' => config('system.package_category')[0]]) }}"><i
                                class="fa fa-fax"></i> <span> {{ $item->name }}</span></a></li>
                @endforeach
            @endcan
            @else
                @can('package')
                    <li class="header">套系管理</li>
                    <li @if(app('request')->routeIs('admin.package.explosive*')) class="active" @endif><a
                            href="{{ route("admin.package.explosive") }}"><i class="fa fa-database"></i>
                            <span>爆款套系</span></a></li>
                    <li class="treeview">
                      <a id="dropdownSubMenu1" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link dropdown-toggle"><i class="fa fa-bookmark-o"></i> <span>摄影门店</span></a>
                      <ul aria-labelledby="dropdownSubMenu1" class="treeview-menu">
                        @foreach(Shop::query()->where('type', Shop::TYPE_PHOTO)->get() as $item)
                            <li @if((app('request')->routeIs('admin.package*') || app('request')->routeIs('admin.recharge*')) && (isset($shopId) && $shopId == $item->id)) class="active" @endif>
                                <a href="{{ route("admin.package.index", ['shop_id' => $item->id, 'category' => config('system.package_category')[0]]) }}"><i
                                        class="fa fa-fax"></i> <span> {{ $item->name }}</span></a></li>
                        @endforeach
                      </ul>
                    </li>
                    
                @endcan
            @endif

            @if ($user->is_merchant_staff == Admin::MERCHANT_AUTH) {{-- 如果是1的话，则是商家职员 --}}
            @can('merchant_staff_goods_and_package')
                <li class="header">商品管理</li>
                @foreach(Shop::query()->whereIn("id",json_decode($user->shop_id,true))->where([["type",'!=',Shop::TYPE_PHOTO]])->get() as $item)
                    <li @if(app('request')->routeIs('admin.good*') && isset($shopId) && $shopId == $item->id) class="active" @endif>
                        <a href="{{ route("admin.good.index", ['shop_id' => $item->id]) }}"><i class="fa fa-fax"></i>
                            <span>{{ $item->name }}</span></a></li>
                @endforeach
            @endcan
            @else
                @can('good')
                    <li class="header">商品管理</li>
                    @can('good-top_category')
                        <li @if(app('request')->routeIs('admin.category*')) class="active" @endif><a
                                href="{{ route("admin.category.index") }}"><i class="fa fa-database"></i>
                                <span>商品分类</span></a>
                        </li>
                    @endcan
                    <!-- @can('good-brand')
                        <li @if(app('request')->routeIs('admin.brand*')) class="active" @endif><a
                                href="{{ route("admin.brand.index") }}"><i class="fa fa-database"></i> <span>商品品牌</span></a>
                        </li>
                    @endcan -->

                    <li class="treeview">
                      <a id="dropdownSubMenu1" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link dropdown-toggle"><i class="fa fa-bookmark-o"></i> <span>商品门店</span></a>
                      <ul aria-labelledby="dropdownSubMenu1" class="treeview-menu">
                        @foreach(Shop::query()->where('type', "!=", Shop::TYPE_PHOTO)->get() as $item)
                            <li @if((app('request')->routeIs('admin.good*') || app('request')->routeIs('admin.recharge*') || app('request')->routeIs('admin.brand*') || app('request')->routeIs('admin.tag*')) && (isset($shopId) && $shopId == $item->id)) class="active" @endif>
                                <a href="{{ route("admin.good.index", ['shop_id' => $item->id]) }}"><i
                                        class="fa fa-fax"></i>
                                    <span>{{ $item->name }}</span></a></li>
                        @endforeach
                      </ul>
                    </li>

                @endcan
            @endif

            @if ($user->is_merchant_staff == Admin::MERCHANT_AUTH) {{-- 如果是1的话，则是商家职员 --}}
                <li class="header">营销管理</li>
                <li @if(app('request')->routeIs('admin.full_reduction*')) class="active" @endif><a
                        href="{{ route("admin.full_reduction.index") }}"><i class="fa fa-database"></i>
                        <span>满减优惠</span></a>
                </li>

                <li @if(app('request')->routeIs('admin.discount*')) class="active" @endif><a
                        href="{{ route("admin.discount.index") }}"><i class="fa fa-database"></i> 
                        <span>商品折扣</span></a>
                </li>

                @if(in_array(1, $shops))
                <!-- $shops 当前登录员工账号所绑定的门店，查看是否包含婚纱门店 -->
                <li @if(app('request')->routeIs('admin.gift*')) class="active" @endif><a
                        href="{{ route("admin.gift.index") }}"><i class="fa fa-database"></i> 
                        <span>套系赠品</span></a>
                </li>
                @endif

                @if(in_array(0, $shops))
                <!-- $shops 当前登录员工账号所绑定的门店，查看是否包含非婚纱门店 -->
                <li @if(app('request')->routeIs('admin.goods_gift*')) class="active" @endif><a
                        href="{{ route("admin.goods_gift.index") }}"><i class="fa fa-database"></i>
                        <span>商品赠品</span></a>
                </li>
                @endif
            @else

            {{--@can('coupon')--}}
                <li class="header">营销管理</li>
                {{--                <li @if(app('request')->routeIs('admin.coupon*')) class="active" @endif><a href="{{ route("admin.coupon.index") }}"><i class="fa fa-database"></i> <span>优惠券管理</span></a></li>--}}
                <li @if(app('request')->routeIs('admin.full_reduction*')) class="active" @endif><a
                        href="{{ route("admin.full_reduction.index") }}"><i class="fa fa-database"></i>
                        <span>满减优惠</span></a></li>
                <li @if(app('request')->routeIs('admin.discount*')) class="active" @endif><a
                        href="{{ route("admin.discount.index") }}"><i class="fa fa-database"></i> <span>商品折扣</span></a>
                </li>
                <li @if(app('request')->routeIs('admin.gift*')) class="active" @endif><a
                        href="{{ route("admin.gift.index") }}"><i class="fa fa-database"></i> <span>套系赠品</span></a></li>
                <li @if(app('request')->routeIs('admin.goods_gift*')) class="active" @endif><a
                        href="{{ route("admin.goods_gift.index") }}"><i class="fa fa-database"></i>
                        <span>商品赠品</span></a></li>
            {{--@endcan--}}
            @endif

            @if ($user->is_merchant_staff == Admin::MERCHANT_AUTH) {{-- 如果是1的话，则是商家职员 --}}
                @can('merchant_staff_order')
                    <li class="header">销售管理</li>
                    @php
                        $orderShop = Shop::query()->where("id",$user->shop_id)->first();
                    @endphp
                    @php
                        $shop = Shop::query()->whereIn("id",json_decode($user->shop_id,true))->get();
                        $package=0;$good = 0;
                        foreach ($shop as $s){
                            if($s->is_photography == 1){
                                $package++;
                            }
                             if($s->is_photography == 0){
                                $good++;
                            }
                        }
                    @endphp
                    @if ($package >0 && $good>0)
                        <li @if(app('request')->routeIs('admin.order*')) class="active" @endif><a
                                href="{{ route("admin.order.package_index",["merchant"=>1]) }}"><i
                                    class="fa fa-database"></i>
                                <span>订单管理</span></a>
                        </li>
                    @elseif($good>0)
                        <li @if(app('request')->routeIs('admin.order*')) class="active" @endif><a
                                href="{{ route("admin.order.good_index",["merchant"=>1]) }}"><i class="fa fa-database"></i>
                                <span>订单管理</span></a>
                        </li>
                    @elseif($package>0)
                        <li @if(app('request')->routeIs('admin.order*')) class="active" @endif><a
                                href="{{ route("admin.order.package_index",["merchant"=>1]) }}"><i class="fa fa-database"></i>
                                <span>订单管理</span></a>
                        </li>
                    @endif


                @endcan
            @else
                @can('order')
                    <li class="header">销售管理</li>
                    <li @if(app('request')->routeIs('admin.order*')) class="active" @endif><a
                            href="{{ route("admin.order.package_index") }}"><i class="fa fa-database"></i>
                            <span>订单管理</span></a>
                    </li>
                @endcan
            @endif


            @can('crowd')
                <li @if(app('request')->routeIs('admin.crowd*')) class="active" @endif><a
                        href="{{ route("admin.crowd.index") }}"><i class="fa fa-database"></i> <span>众筹管理</span></a>
                </li>
            @endcan
            {{--            @can('team')--}}
            {{--                <li @if(app('request')->routeIs('admin.team*')) class="active" @endif><a href="{{ route("admin.team.index") }}"><i class="fa fa-database"></i> <span>团队数据</span></a></li>--}}
            {{--            @endcan--}}

            @can('comment')
                <li class="header">评论管理</li>
                <li @if(app('request')->routeIs('admin.comment*')) class="active" @endif><a
                        href="{{ route("admin.comment.index") }}"><i class="fa fa-database"></i> <span>评论管理</span></a>
                </li>
            @endcan

            @can('recharge_record')
                <li class="header">充值管理</li>
                <li @if(app('request')->routeIs('admin.rechargeRecord*')) class="active" @endif><a
                        href="{{ route("admin.rechargeRecord.index") }}"><i class="fa fa-database"></i>
                        <span>充值记录</span></a></li>
            @endcan

            <li class="header">用户管理</li>
            @can('user')
                <li @if(app('request')->routeIs('admin.user*')) class="active" @endif><a
                        href="{{ route("admin.user.all") }}"><i class="fa fa-database"></i> <span>用户管理</span></a></li>
            @endcan


            @if ($user->is_merchant_staff == Admin::MERCHANT_AUTH) {{-- 如果是1的话，则是商家职员 --}}
            @can('merchant_staff_rebate')
                <li @if(app('request')->routeIs('admin.rebate*')) class="active" @endif><a
                        href="{{ route("admin.rebate.index",["merchant"=>1]) }}"><i class="fa fa-database"></i> <span>返利管理</span></a>
                </li>
            @endcan
            @else
                @can('rebate')
                    <li @if(app('request')->routeIs('admin.rebate*')) class="active" @endif><a
                            href="{{ route("admin.rebate.index") }}"><i class="fa fa-database"></i>
                            <span>返利管理</span></a>
                    </li>
                @endcan
            @endif


            @can('withdrawal')
                <li @if(app('request')->routeIs('admin.withdrawal*')) class="active" @endif><a
                        href="{{ route("admin.withdrawal.index") }}"><i class="fa fa-database"></i>
                        <span>提现管理</span></a></li>
            @endcan

            @can('feedback')
                @php
                    $count=\App\Modules\User\Models\Feedback::query()->where("read_noread",0)->count();
                @endphp
                <li @if(app('request')->routeIs('admin.feedback*')) class="active" @endif><a
                        href="{{ route("admin.feedback.index") }}"><i class="fa fa-database"></i> <span>用户投诉 <span
                                class="pull-right-container"><small
                                    class="badge pull-right bg-red">{{$count}}</small></span></span></a>
                </li>
            @endcan

            @can('personnel')
                <li class="header">系统设置</li>
                <li @if(app('request')->routeIs('admin.personnel*')) class="active" @endif><a
                        href="{{ route("admin.personnel.index") }}"><i class="fa fa-database"></i> <span>工作人员</span></a>
                </li>
            @endcan

            @can('system')
                <li @if(app('request')->routeIs('admin.system*')) class="active" @endif><a
                        href="{{ route('admin.system.banner') }}"><i class="fa fa-database"></i> <span>系统设置</span></a>
                </li>
            @endcan

            @can('authority')
                <li @if(app('request')->routeIs('admin.authority*')) class="active" @endif><a
                        href="{{ route("admin.authority.role") }}"><i class="fa fa-database"></i> <span>权限管理</span></a>
                </li>
            @endcan

            @can('template')
                <li @if(app('request')->routeIs('admin.template*')) class="active" @endif><a
                        href="{{ route("admin.template.index") }}"><i class="fa fa-database"></i> <span>模板消息</span></a>
                </li>
            @endcan

            {{--            @can('video')--}}
            {{--                <li @if(app('request')->routeIs('admin.video*')) class="active" @endif><a href="{{ route("admin.video.index") }}"><i class="fa fa-database"></i> <span> 视频管理</span></a></li>--}}
            {{--            @endcan--}}

        </ul>
        <!-- /.sidebar-menu -->
    @endauth
</section>
